﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using GrayParrot.Web.Controls;
using GrayParrot.Core.Filters;
using Test.DAL;


namespace FimetContoDeposito.BLL.ResultSets
{
    public class EmployeesResultSet : ResultSet<Employee>
	{
        public EmployeesResultSet(DTParameters param, IQueryable<Employee> result)
            : base(param, result)
        {
        }

        public override Expression<Func<Employee, bool>> ApplyGeneralFilter(string searchPattern)
        {
            var predicate = PredicateBuilder.False<Employee>();

            if (!string.IsNullOrWhiteSpace(searchPattern))
            {
                predicate = predicate.Or(im => im.FirstName != null && im.FirstName.ToString().Contains(searchPattern));
                predicate = predicate.Or(im => im.LastName != null && im.LastName.ToString().Contains(searchPattern));
                predicate = predicate.Or(im => im.Title != null && im.Title.ToString().Contains(searchPattern));
            }

            return predicate;
        }

        public override Expression<Func<Employee, bool>> ApplyGeneralColumnsFilter(List<string> columnSearch)
        {
            var predicate = PredicateBuilder.True<Employee>();

            //string m_id = columnSearch[ColumnIndex];
            //string m_firstName = columnSearch[1 + m_stepForMulti];
            //string m_lastName = columnSearch[2 + m_stepForMulti];
            //string m_title = columnSearch[3 + m_stepForMulti];

            string m_firstName = GetElement(1);
            string m_lastName = GetElement(2);
            string m_title = GetElement(3);

            if (!string.IsNullOrWhiteSpace(m_title))
            {
                predicate = predicate.And(im => im.Title.Contains(m_title));
            }

            if (!string.IsNullOrWhiteSpace(m_firstName))
            {
                predicate = predicate.And(im => im.FirstName.Contains(m_firstName));
            }

            if (!string.IsNullOrWhiteSpace(m_lastName))
            {
                predicate = predicate.And(im => im.LastName.Contains(m_lastName));
            }

            return predicate;
        }
	}
}
